{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "%matplotlib inline \n",
    "%load_ext autoreload \n",
    "%autoreload 2\n",
    "\n",
    "__author__ = 'Song Huang'\n",
    "__email__ = 'shuang89@ucsc.edu'\n",
    "__version__ = '170505A'\n",
    "\n",
    "from __future__ import (print_function, division, absolute_import)\n",
    "\n",
    "import os\n",
    "import sys\n",
    "import math\n",
    "import glob\n",
    "import copy\n",
    "import warnings\n",
    "import subprocess\n",
    "\n",
    "import numpy as np\n",
    "#import seaborn as sns\n",
    "#sns.set(color_codes=True, style=\"darkgrid\")\n",
    "\n",
    "# Matplotlib related\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "#mpl.style.use('classic')\n",
    "plt.rc('text', usetex=True)\n",
    "#plt.rc('font', family='serif')\n",
    "\n",
    "from astropy.io import fits\n",
    "from astropy.table import \\\n",
    "    Table, \\\n",
    "    Column, \\\n",
    "    vstack, \\\n",
    "    unique\n",
    "    \n",
    "from astropy.utils.metadata import MergeConflictWarning\n",
    "warnings.filterwarnings('ignore', category=MergeConflictWarning, \n",
    "                        append=True)\n",
    "from astropy import units as u\n",
    "from astropy.coordinates import SkyCoord\n",
    "from astropy.utils.console import ProgressBar\n",
    "\n",
    "import hsc_massive\n",
    "from hsc_massive import \\\n",
    "    s16a_path, \\\n",
    "    sample_selection, \\\n",
    "    prepare_sed, \\\n",
    "    catalog_summary, \\\n",
    "    smhm, \\\n",
    "    plotting\n",
    "\n",
    "#envir = s16a_path.set_env(version='astro4')\n",
    "envir = s16a_path.set_env(version='kungpao')\n",
    "\n",
    "ORG = plotting.ORG\n",
    "BLK = plotting.BLK\n",
    "BLU = plotting.BLU\n",
    "GRN = plotting.GRN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from numba import jit, void, double\n",
    "\n",
    "from kungpao.isophote.ellipse import Ellipse\n",
    "from kungpao.isophote.ellipse import Centerer\n",
    "from kungpao.isophote.ellipse import Geometry\n",
    "from kungpao.isophote.ellipse.model import build_model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test Numba"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "xx = np.random.random((2000, 2000))\n",
    "yy = np.random.random((2000, 2000))\n",
    "\n",
    "def testA(x, y):\n",
    "    return np.sqrt(x) * np.log10(y) + np.exp(x)\n",
    "\n",
    "@jit \n",
    "def testB(x, y):\n",
    "    return np.sqrt(x) * np.log10(y) + np.exp(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 loops, best of 3: 104 ms per loop\n",
      "10 loops, best of 3: 66.5 ms per loop\n"
     ]
    }
   ],
   "source": [
    "%timeit testA(xx, yy)\n",
    "%timeit testB(xx, yy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 loops, best of 3: 105 ms per loop\n"
     ]
    }
   ],
   "source": [
    "testA_numba = jit(void(double[:], double[:,:]))(testA)\n",
    "\n",
    "%timeit testA_numba(xx, yy)"
   ]
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  },
  "nav_menu": {},
  "toc": {
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 6,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
